home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / terms / tipx / xfer / zcurses.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-11  |  27.8 KB  |  1,165 lines

  1. /*+-------------------------------------------------------------------------
  2.     zcurses.c -- tip file transfer program curses interface
  3.     wht%n4hgf@emory.mathcs.emory.edu
  4.  
  5.   000000000011111111112222222222333333333344444444445555555550
  6.   012345678901234567890123456789012345678901234567890123456789
  7. 00.-[ prog+rev ]-- <dir> ------------------------------------.
  8. 01|  ZMODEM_6____  _40_____________________________________  |
  9. 02|  File ### of ###: _38__________________________________  |
  10. 03|  File position:  _8______ length: _8______  -rwxrwxrwx   |
  11. 04|  _55____________________________________________________ | transaction
  12. 05|  _55____________________________________________________ | last rx/tx hdr
  13. 06|  Comm I/O: rx _8______  tx _8______ bytes                |
  14. 07|  Baud rate: _5___ BINARY blklen: _____ comm mode: RAW-g  |
  15. 08|  Time:    started: __:__:__ this file: __:__:__ window:  |
  16. 09|  __:__:__ elapsed: __:__:__            __:__:__ ________ |
  17. 10|  Errors: this file: _3_ total: _4__ files skipped: _3_   |
  18. 11|  _55____________________________________________________ |  err str
  19. 12|  _55____________________________________________________ |  comment str
  20. 13|  _55____________________________________________________ |  remote info
  21. 14`----------------------------------------------------------'
  22.  
  23.   Defined functions:
  24.     clear_area(win,row,col,len)
  25.     clear_area_char(win,row,col,len,fillchar)
  26.     get_elapsed_time(elapsed_seconds)
  27.     get_tod(type,tod)
  28.     mode_map(mode,mode_str)
  29.     report_comm_baud_rate(baud_rate)
  30.     report_error_count()
  31.     report_file_byte_io(count)
  32.     report_file_close()
  33.     report_file_open_length(length)
  34.     report_file_open_mode(file_mode)
  35.     report_file_open_tod()
  36.     report_file_rcv_started(filename,length,last_mod_time,file_mode)
  37.     report_file_send_open(filename,filestat)
  38.     report_init(title)
  39.     report_last_rxhdr(rptstr,error_flag)
  40.     report_last_txhdr(rptstr,error_flag)
  41.     report_mode(mode)
  42.     report_protocol_crc_type(str)
  43.     report_protocol_type(str)
  44.     report_rx_ind(status)
  45.     report_rx_tx_count()
  46.     report_rxblklen(blklen)
  47.     report_rxpos(rxpos)
  48.     report_str(rptstr,error_flag)
  49.     report_top_line(topstr)
  50.     report_transaction(str)
  51.     report_tx_ind(status)
  52.     report_txblklen(blklen)
  53.     report_txpos(txpos)
  54.     report_uninit(sig)
  55.     report_window()
  56.     report_xfer_mode(str)
  57.  
  58. ------------------------------------------------------------------------*/
  59. /*+:EDITS:*/
  60. /*:08-23-1990-13:55-wht@tridom-enable rx/tx ind */
  61. /*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
  62.  
  63. #include <curses.h>
  64. #include <sys/types.h>
  65. #include <sys/stat.h>
  66. #include <ctype.h>
  67. #include <signal.h>
  68. #include <time.h>
  69. #include <sys/timeb.h>
  70.  
  71. #include "zlint.h"
  72.  
  73. long time();
  74. extern char *tzname[];
  75. struct tm *localtime();
  76.  
  77. #ifdef IBMPC
  78. #define sTL        0xDA
  79. #define sTR        0xBF
  80. #define sBL        0xC0
  81. #define sBR        0xD9
  82. #define sLT        0xC3    /* left hand T */
  83. #define sRT        0xB4    /* right hand T */
  84. #define sVR        0xB3    /* vertical rule */
  85. #define sHR        0xC4    /* horizontal rule */
  86. #else
  87. #define sTL        '.'
  88. #define sTR        '.'
  89. #define sBL        '`'
  90. #define sBR        '\''
  91. #define sLT        '+'
  92. #define sRT        '+'
  93. #define sVR        '|'
  94. #define sHR        '-'
  95. #endif
  96.  
  97. #define WIN_LINES    15
  98. #define WIN_COLS    60
  99. #define WIN_TOPY    2
  100. #define WIN_LEFTX    8
  101.  
  102. extern char curr_dir[];
  103. extern char s128[];
  104. extern char *bottom_label;
  105. extern int Filcnt;
  106. extern int tipsz_flag;    /* tipsz == 1, tiprz == 0 */
  107. extern int skip_count;
  108. extern int npats;
  109. extern long rxpos;
  110. extern int log_packets;
  111. extern long Txpos;
  112. extern long Rxpos;
  113.  
  114. WINDOW    *win;
  115. int (*original_sigint_handler)();
  116. int (*original_sigquit_handler)();
  117. int (*original_sigterm_handler)();
  118. int curses_installed = 0;        /* curses not yet active */
  119. int this_file_errors;
  120. int total_errors;
  121. int show_window = 0;
  122. long current_seconds = 0;
  123. long start_seconds = 0;
  124. long this_file_start_seconds = 0;
  125. long elapsed_seconds = 0;
  126. unsigned long total_data_chars_xfered = 0L;
  127. unsigned int zcurses_baud_rate = 0;
  128. char s256[256];
  129.  
  130. char *win_template[] =
  131. {
  132. /*00000000001111111111222222222233333333334444444444555555555 */
  133. /*01234567890123456789012345678901234567890123456789012345678 */
  134. /*.----------------------------------------------------------. */
  135.   "                                                          ",    /* 1 */
  136.   "  File ### of ###: _____________________________________  ",    /* 2 */
  137.   "  File position:  ________ length: ________               ",    /* 3 */
  138.   "                                                          ",    /* 4 */
  139.   "  tx: ______________________  rx: ______________________  ",    /* 5 */
  140.   "  Comm I/O: rx ________  tx ________ bytes                ",    /* 6 */
  141.   "  Baud rate: _____ ______ blklen: _____ comm mode: ______ ",    /* 7 */
  142.   "  Time:    started: __:__:__ this file: __:__:__          ", /* 8 */
  143.   "  __:__:__ elapsed: __:__:__            __:__:__          ", /* 9 */
  144.   "  Errors: this file: ___ total: ____ files skipped: ___   ", /* 10 */
  145.   "                                                          ",    /* 11 */
  146.   "                                                          ",    /* 12 */
  147.   "                                                          ",    /* 13 */
  148. /*`----------------------------------------------------------' */
  149. (char *)0
  150. };
  151.  
  152. /*+-----------------------------------------------------------------------
  153.     char *get_elapsed_time(elapsed_seconds)
  154.     hh:mm:ss returned
  155.   static string address is returned
  156. ------------------------------------------------------------------------*/
  157. char *get_elapsed_time(elapsed_seconds)
  158. long elapsed_seconds;
  159. {
  160.     static char elapsed_time_str[10];
  161.     long hh,mm,ss;
  162.  
  163.     hh = elapsed_seconds / 3600;
  164.     elapsed_seconds -= hh * 3600;
  165.     mm = elapsed_seconds / 60L;
  166.     elapsed_seconds -= mm * 60L;
  167.     ss = elapsed_seconds;
  168.  
  169.     sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);
  170.     return(elapsed_time_str);
  171. }    /* end of get_elapsed_time */
  172.  
  173. /*+-----------------------------------------------------------------------
  174.     char *get_tod(type,tod)
  175.  
  176.   time of day types:
  177.     0        hh:mm
  178.     1        hh:mm:ss
  179.     2        mm-dd-yyyy hh:mm
  180.  
  181.   static string address is returned
  182.   if tod != (char *)0, time is returned there too
  183. ------------------------------------------------------------------------*/
  184. char *
  185. get_tod(type,tod)
  186. int type;
  187. char *tod;
  188. {
  189.     long cur_time = 0;
  190.     struct tm *lt;            /* local time */
  191.     static char tod_str[32];
  192. #if defined(M_SYS5)
  193.     struct timeb tp;
  194. #endif
  195.  
  196.     cur_time = time((long *)0);
  197.     lt = localtime(&cur_time);
  198.  
  199.     switch(type)
  200.     {
  201.     case 0:
  202.         sprintf(tod_str,"%02d:%02d",lt->tm_hour,lt->tm_min);
  203.         break;
  204.  
  205.     default:
  206.     case 1:
  207.         sprintf(tod_str,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec);
  208.         break;
  209.  
  210.     case 2:
  211.         sprintf(tod_str,"%02d-%02d-%04d %02d:%02d",
  212.             lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
  213.             lt->tm_hour,lt->tm_min);
  214.         break;
  215.     }
  216.  
  217.     if(tod != (char *)0)
  218.         strcpy(tod,tod_str);
  219.  
  220.     return(tod_str);
  221. }    /* end of get_tod */
  222.  
  223. /*+-----------------------------------------------------------------------
  224.     mode_map(mode,mode_str)    build drwxrwxrwx string
  225. ------------------------------------------------------------------------*/
  226. char *
  227. mode_map(mode,mode_str)
  228. unsigned short mode;
  229. char *mode_str;
  230. {
  231. register unsigned ftype = mode & S_IFMT;
  232. register char *rtn;
  233. static char result[12];
  234.  
  235.     rtn = (mode_str == (char *)0) ? result : mode_str;
  236.  
  237.     /*               drwxrwxrwx */
  238.     /*               0123456789 */
  239.     strcpy(rtn,"----------");
  240.  
  241.     switch(ftype)
  242.     {
  243.         case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  244.         case S_IFDIR:    *rtn = 'd'; break; /* directory */
  245.         case S_IFCHR:    *rtn = 'c'; break; /* character special */
  246.         case S_IFBLK:    *rtn = 'b'; break; /* block special */
  247.         case S_IFREG:    *rtn = '-'; break; /* regular */
  248.  
  249. #if defined(V7) | defined(BSD4)
  250.         case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  251.         case S_IFSOCK:    *rtn = 's'; break; /* socket */
  252. #endif
  253.  
  254. #if defined(M_SYS5)
  255.         case S_IFNAM:                        /* name space entry */
  256.             if(mode & S_INSEM)                /* semaphore */
  257.             {
  258.                 *rtn = 's';
  259.                 break;
  260.             }
  261.             if(mode & S_INSHD)                /* shared memory */
  262.             {
  263.                 *rtn = 'm';
  264.                 break;
  265.             }
  266. #endif
  267.  
  268.         default:        *rtn = '?'; break;    /* ??? */
  269.     }
  270.  
  271.     if(mode & 000400) *(rtn + 1) = 'r';
  272.     if(mode & 000200) *(rtn + 2) = 'w';
  273.     if(mode & 000100) *(rtn + 3) = 'x';
  274.     if(mode & 004000) *(rtn + 3) = 's';
  275.     if(mode & 000040) *(rtn + 4) = 'r';
  276.     if(mode & 000020) *(rtn + 5) = 'w';
  277.     if(mode & 000010) *(rtn + 6) = 'x';
  278.     if(mode & 002000) *(rtn + 6) = 's';
  279.     if(mode & 000004) *(rtn + 7) = 'r';
  280.     if(mode & 000002) *(rtn + 8) = 'w';
  281.     if(mode & 000001) *(rtn + 9) = 'x';
  282.     if(mode & 001000) *(rtn + 9) = 't';
  283.  
  284.     return(rtn);
  285.  
  286. }    /* end of mode_map */
  287.  
  288. /*+-------------------------------------------------------------------------
  289.     clear_area(win,row,col,len)
  290. --------------------------------------------------------------------------*/
  291. clear_area(win,row,col,len)
  292. WINDOW    *win;
  293. int row;
  294. int col;
  295. int len;
  296. {
  297.     wmove(win,row,col);
  298.     while(len-- > 0)
  299.         waddch(win,' ');
  300.     wmove(win,row,col);
  301.  
  302. }    /* end of clear_area */
  303.  
  304. /*+-------------------------------------------------------------------------
  305.     clear_area_char(win,row,col,len,fillchar)
  306. --------------------------------------------------------------------------*/
  307. clear_area_char(win,row,col,len,fillchar)
  308. WINDOW    *win;
  309. int row;
  310. int col;
  311. int len;
  312. char fillchar;
  313. {
  314.     wmove(win,row,col);
  315.     while(len-- > 0)
  316.         waddch(win,fillchar);
  317.     wmove(win,row,col);
  318.  
  319. }    /* end of clear_area_char */
  320.  
  321. /*+-------------------------------------------------------------------------
  322.     report_top_line(topstr)
  323.    top line: row 1 col 17 length 42
  324. --------------------------------------------------------------------------*/
  325. void
  326. report_top_line(topstr)
  327. char *topstr;
  328. {
  329. char s42[42];
  330.     clear_area(win,1,17,42);
  331.     if(strlen(topstr) < 40)
  332.         waddstr(win,topstr);
  333.     else
  334.     {
  335.         strncpy(s42,topstr,40);
  336.         s42[40] = 0;
  337.         waddstr(win,s42);
  338.     }
  339. }    /* end of report_top_line */
  340.  
  341. /*+-------------------------------------------------------------------------
  342.     report_xfer_mode(modestr)  BINARY/ASCII
  343.    protocol xfer type: row 7 col 20 length 6
  344. --------------------------------------------------------------------------*/
  345. report_xfer_mode(str)
  346. char *str;
  347. {
  348. char s10[10];
  349.  
  350.     if(strlen(str) > 6)
  351.     {
  352.         strncpy(s10,str,6);
  353.         s10[7] = 0;
  354.         str = s10;
  355.     }
  356.     clear_area(win,7,20,6);
  357.     waddstr(win,str);
  358.     wrefresh(win);
  359.  
  360. }    /* end of report_xfer_mode */
  361.  
  362. /*+-------------------------------------------------------------------------
  363.     report_protocol_type(str)
  364.  
  365.   protocol type:  row 1 col 3 length 6 string
  366. --------------------------------------------------------------------------*/
  367. report_protocol_type(str)
  368. register char *str;
  369. {
  370. char s10[10];
  371.  
  372.     if(strlen(str) > 6)
  373.     {
  374.         strncpy(s10,str,6);
  375.         s10[7] = 0;
  376.         str = s10;
  377.     }
  378.     clear_area(win,1,3,6);
  379.     waddstr(win,str);
  380.     wrefresh(win);
  381.  
  382. }    /* end of report_protocol_type */
  383.  
  384. /*+-------------------------------------------------------------------------
  385.     report_protocol_crc_type(str)
  386.  
  387.   protocol crc type:  row 1 col 9 length 6
  388. --------------------------------------------------------------------------*/
  389. report_protocol_crc_type(str)
  390. register char *str;
  391. {
  392. char s8[8];
  393.  
  394.     if(strlen(str) > 6)
  395.     {
  396.         strncpy(s8,str,6);
  397.         s8[7] = 0;
  398.         str = s8;
  399.     }
  400.     clear_area(win,1,9,6);
  401.     waddstr(win,str);
  402.     wrefresh(win);
  403.  
  404. }    /* end of report_protocol_crc_type */
  405.  
  406. /*+-------------------------------------------------------------------------
  407.     report_uninit(sig)
  408. --------------------------------------------------------------------------*/
  409. void
  410. report_uninit(sig)
  411. int sig;        /* if -1, called by normal code, else kill() value */
  412. {
  413.     float rate = 0.0;
  414.     float eff = 0.0;
  415.  
  416.     if(curses_installed)
  417.     {
  418.         elapsed_seconds = current_seconds - start_seconds;
  419.         if(elapsed_seconds)
  420.         {
  421.             rate = (float)total_data_chars_xfered / (float)elapsed_seconds;
  422.             if(zcurses_baud_rate)
  423.                 eff  = 100 * (rate / ((float)zcurses_baud_rate / 10.0));
  424.         }
  425.         if(rate > 0.01)
  426.         {
  427.             sprintf(s128,"Transfer rate ~= %.0f ch/sec (%.0f%%)",
  428.                 rate,(eff > 0.5) ? eff : 0.0);
  429.             if(log_packets)
  430.             {
  431.                 write(log_packets,"info: ",6);
  432.                 write(log_packets,s128,strlen(s128));
  433.                 write(log_packets,"\n",1);
  434.             }
  435.             report_top_line(s128);
  436.         }
  437.         report_file_byte_io(0L);
  438.         report_rx_tx_count();
  439.         wmove(win,WIN_LINES - 1,WIN_COLS - 1);
  440.         wrefresh(win);
  441.         endwin();
  442.         fprintf(stderr,"\r\n\r\n\r\n");
  443.         fflush(stderr);
  444.         curses_installed = 0;
  445.     }
  446.  
  447. }    /* end of report_uninit */
  448.  
  449. /*+-------------------------------------------------------------------------
  450.     report_init(title)
  451.   "top line": row 1 col 11 len 21
  452.   file quan:  row 2 col 15 len  3
  453.               row 2 col 12 len  7 clear "of ###"
  454.   start time: row 8 col 21 len  8
  455.   "window:"   row 8 col 50 len  7
  456. --------------------------------------------------------------------------*/
  457. void
  458. report_init(title)
  459. char *title;
  460. {
  461.     register int itmp;
  462.     register char *cptr;
  463.     char buf[80];
  464.  
  465.     if(curses_installed)
  466.         return;
  467.  
  468.     initscr();
  469.     crmode();
  470.     noecho();
  471.     nonl();
  472.     clear();
  473.     curses_installed = 1;
  474.     win = newwin(WIN_LINES,WIN_COLS,WIN_TOPY,WIN_LEFTX);
  475.     box(win,sVR,sHR);
  476.     wmove(win,0,0); waddch(win,sTL);
  477.     wmove(win,win->_maxy - 1,0); waddch(win,sBL);
  478.     wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,sBR);
  479.     wmove(win,0,win->_maxx - 1); waddch(win,sTR);
  480.     wmove(win,0,2);
  481.     wstandout(win);
  482.     waddch(win,'[');
  483.     waddch(win,' ');
  484.     waddstr(win,title);
  485.     waddch(win,' ');
  486.     waddch(win,']');
  487.     wstandend(win);
  488.     waddch(win,sHR);
  489.     waddch(win,sHR);
  490.     waddch(win,' ');
  491.     itmp = WIN_COLS - 2 - 7 - strlen(title);
  492.     curr_dir[itmp] = 0;
  493.     waddstr(win,curr_dir);
  494.     waddch(win,' ');
  495.     if(bottom_label)
  496.     {
  497.         strncpy(buf,bottom_label,WIN_COLS - 6);
  498.         buf[WIN_COLS - 6] = 0;
  499.         wmove(win,WIN_LINES - 1,2);
  500.         waddch(win,' ');
  501.         waddstr(win,buf);
  502.         waddch(win,' ');
  503.     }
  504.  
  505.     itmp = 0;
  506.     while(1)
  507.     {
  508.         if(win_template[itmp] == (char *)0)
  509.             break;
  510.         wmove(win,itmp + 1,1);
  511.         waddstr(win,win_template[itmp++]);
  512.     }
  513.     if(tipsz_flag)
  514.     {
  515.         clear_area(win,2,15,3);
  516.         sprintf(s128,"%3d",npats);
  517.         waddstr(win,s128);
  518.     }
  519.     else    /* tiprz */
  520.     {
  521.         clear_area(win,2,11,8);    /* clear "of ###" */
  522.         waddstr(win,":");
  523.     }
  524.  
  525.     clear_area(win,1,11,21);
  526.     report_error_count();
  527.     clear_area(win,8,21,8);        /* starting time */
  528.     waddstr(win,get_tod(1,(char *)0));
  529.     start_seconds = time((long *)0);
  530.     current_seconds = start_seconds;
  531.  
  532.     if(show_window)
  533.     {
  534.         wmove(win,8,50);
  535.         waddstr(win,"window:");
  536.         wmove(win,9,50);
  537.         waddstr(win,"+0");
  538.     }
  539.  
  540.     wrefresh(win);
  541.  
  542. }    /* end of report_init */
  543.  
  544. /*+-------------------------------------------------------------------------
  545.     report_rx_ind(status)
  546. --------------------------------------------------------------------------*/
  547. void
  548. report_rx_ind(status)
  549. int status;
  550. {
  551.     wmove(win,1,54);
  552.     waddch(win,(status) ? 'R' : ' ');
  553.     wmove(win,1,54);
  554.     wrefresh(win);
  555. }    /* end of report_rx_ind */
  556.  
  557. /*+-------------------------------------------------------------------------
  558.     report_tx_ind(status)
  559. --------------------------------------------------------------------------*/
  560. void
  561. report_tx_ind(status)
  562. int status;
  563. {
  564.     wmove(win,1,56);
  565.     waddch(win,(status) ? 'T' : ' ');
  566.     wmove(win,1,56);
  567.     wrefresh(win);
  568. }    /* end of report_tx_ind */
  569.  
  570. /*+-------------------------------------------------------------------------
  571.     report_window() - if enable, show open widow size
  572. --------------------------------------------------------------------------*/
  573. void
  574. report_window()
  575. {
  576.     if(show_window)
  577.     {
  578.     long ltmp;
  579.         wmove(win,9,50);
  580.         if((ltmp = (Txpos - Rxpos)) > 999999L)
  581.             waddstr(win,">+999999");
  582.         else if(ltmp < -999999L)
  583.             ;
  584.         else
  585.         {
  586.             sprintf(s128,"%+-8ld",ltmp);
  587.             waddstr(win,s128);
  588.             if(log_packets)
  589.             {
  590.                 write(log_packets,"window: ",8);
  591.                 write(log_packets,s128,strlen(s128));
  592.                 write(log_packets,"\n",1);
  593.             }
  594.         }
  595.     }
  596. }    /* end of report_window */
  597.  
  598. /*+-------------------------------------------------------------------------
  599.     report_rx_tx_count()
  600.  
  601.   This procedure may be counted upon to perform wrefresh(win)
  602.  
  603.   rx char count:          row 6 col 16 len 8 unsigned long
  604.   tx char count:          row 6 col 29 len 8 unsigned long
  605.   session elapsed time:   row 9 col 21 len 8
  606.   this file elapsed time: row 9 col 41 len 8
  607.   current tod:            row 9 col  3 len 8
  608.   window:                 row 9 col 50 len 8
  609. --------------------------------------------------------------------------*/
  610. report_rx_tx_count()
  611. {
  612.     extern unsigned long rx_char_count;
  613.     extern unsigned long tx_char_count;
  614.  
  615.     register char *cptr;
  616.  
  617.     sprintf(s128,"%8ld",rx_char_count);
  618.     wmove(win,6,16);
  619.     waddstr(win,s128);
  620.     sprintf(s128,"%8ld",tx_char_count);
  621.     wmove(win,6,29);
  622.     waddstr(win,s128);
  623.  
  624.     /* now time of day */
  625.     wmove(win,9,3);
  626.     cptr = get_tod(1,(char *)0);
  627.     waddstr(win,cptr);
  628.     current_seconds = time((long *)0);
  629.     elapsed_seconds = current_seconds - start_seconds;
  630.     cptr = get_elapsed_time(elapsed_seconds);
  631.     wmove(win,9,21);
  632.     waddstr(win,cptr);
  633.     if(this_file_start_seconds)
  634.         elapsed_seconds = current_seconds - this_file_start_seconds;
  635.     else
  636.         elapsed_seconds = 0;
  637.     cptr = get_elapsed_time(elapsed_seconds);
  638.     wmove(win,9,41);
  639.     waddstr(win,cptr);
  640.  
  641.     report_window();
  642.  
  643.     wrefresh(win);        /* calling procs expect this to occur always */
  644.  
  645. }    /* end of report_rx_tx_count */
  646.  
  647. /*+-------------------------------------------------------------------------
  648.     report_mode(mode)
  649.  
  650.  comm mode row 7 col 52 length 6
  651.    3: save old tty stat, set raw mode with flow control
  652.    2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  653.    1: save old tty stat, set raw mode 
  654.    0: restore original tty mode
  655. --------------------------------------------------------------------------*/
  656. void
  657. report_mode(mode)
  658. int mode;
  659. {
  660. char *cptr;
  661. char tmp[8];
  662.  
  663.     clear_area(win,7,52,6);
  664.     switch(mode)
  665.     {
  666.     case 0:
  667.         cptr = "NORMAL";
  668.         break;
  669.     case 1:
  670.         cptr = "RAW";
  671.         break;
  672.     case 2:
  673.         cptr = "RAW-g";
  674.         break;
  675.     case 3:
  676.         cptr = "RAW-f";
  677.         break;
  678.     default:
  679.         sprintf(tmp,"%5u",mode);
  680.         cptr = tmp;
  681.     }
  682.     waddstr(win,cptr);
  683.     wrefresh(win);
  684.     if(log_packets)
  685.     {
  686.         write(log_packets,"mode: ",6);
  687.         write(log_packets,cptr,strlen(cptr));
  688.         write(log_packets,"\n",1);
  689.     }
  690.  
  691. }    /* end of report_mode */
  692.  
  693. /*+-------------------------------------------------------------------------
  694.     report_rxblklen(blklen) 
  695. row 7 col 35 5 chars
  696. --------------------------------------------------------------------------*/
  697. void
  698. report_rxblklen(blklen)
  699. int blklen;
  700. {
  701.     char tmp[10];
  702.  
  703.     sprintf(tmp,"%5u",blklen);
  704.     clear_area(win,7,35,5);
  705.     waddstr(win,tmp);
  706.     wrefresh(win);
  707. }    /* end of report_rxblklen */
  708.  
  709. /*+-------------------------------------------------------------------------
  710.     report_txblklen(blklen) 
  711. row 7 col 35 5 chars
  712. --------------------------------------------------------------------------*/
  713. void
  714. report_txblklen(blklen)
  715. int blklen;
  716. {
  717.     report_rxblklen(blklen);
  718. }    /* end of report_txblklen */
  719.  
  720. /*+-------------------------------------------------------------------------
  721.     report_rxpos(rxpos) row 3 col 19 len 8
  722. --------------------------------------------------------------------------*/
  723. void
  724. report_rxpos(rxpos)
  725. long rxpos;
  726. {
  727. int i;
  728. char tmp[16];
  729. char rdchar;
  730.     if(
  731. #if defined(M_SYS5)
  732.         rdchk(0)
  733. #else
  734.         !ioctl(0,FIONREAD,&i) && i
  735. #endif
  736.             )
  737.     {
  738.         read(0,&rdchar,1);
  739.         rdchar &= 0x7f;
  740.         if(rdchar == 0x0C || rdchar == 0x012)    /* ^L or ^R */
  741.         {
  742.             touchwin(stdscr);
  743.             wrefresh(stdscr);
  744.             touchwin(win);
  745.             wrefresh(win);
  746.         }
  747.     }
  748.  
  749.     if((rxpos > 99999999L) || (rxpos < 0L))
  750.         return;
  751.  
  752.     sprintf(tmp,"%8lu",rxpos);
  753.     wmove(win,3,19);
  754.     waddstr(win,tmp);
  755.     wrefresh(win);
  756.     report_rx_tx_count();    /* which will do a refresh */
  757. }    /* end of report_rxpos */
  758.  
  759. /*+-------------------------------------------------------------------------
  760.     report_txpos(txpos)
  761. --------------------------------------------------------------------------*/
  762. void
  763. report_txpos(txpos)
  764. long txpos;
  765. {
  766.     report_rxpos(txpos);
  767. }    /* end of report_txpos */
  768.  
  769. /*+-------------------------------------------------------------------------
  770.     report_error_count()
  771.     DOES NOT PERFORM A REFRESH CYCLE
  772.  
  773.   this file: row 10 col 22 len 3
  774.   total:     row 10 col 33 len 4
  775.   skipped:   row 10 col 53 len 3
  776. --------------------------------------------------------------------------*/
  777. report_error_count()
  778. {
  779.     char tmp[16];
  780.  
  781.     wmove(win,10,22);
  782.     sprintf(tmp,"%3d",this_file_errors);
  783.     if(this_file_errors)
  784.         wstandout(win);
  785.     waddstr(win,tmp);
  786.     if(this_file_errors)
  787.         wstandend(win);
  788.  
  789.     wmove(win,10,33);
  790.     sprintf(tmp,"%4d",total_errors);
  791.     if(total_errors)
  792.         wstandout(win);
  793.     waddstr(win,tmp);
  794.     if(total_errors)
  795.         wstandend(win);
  796.  
  797.     wmove(win,10,53);
  798.     sprintf(tmp,"%3d",skip_count);
  799.     waddstr(win,tmp);
  800.     wrefresh(win);
  801.  
  802. }    /* end of report_error_count */
  803.  
  804. /*+-------------------------------------------------------------------------
  805.     report_last_txhdr(rptstr,error_flag)
  806.     5,7,22
  807. --------------------------------------------------------------------------*/
  808. void
  809. report_last_txhdr(rptstr,error_flag)
  810. register char *rptstr;
  811. int error_flag;
  812. {
  813. char s24[24];
  814.  
  815.     if(log_packets)
  816.     {
  817.         write(log_packets,"tx:   ",6);
  818.         write(log_packets,rptstr,strlen(rptstr));
  819.         write(log_packets,"\n",1);
  820.     }
  821.  
  822.     if(strlen(rptstr) > 22)
  823.     {
  824.         strncpy(s24,rptstr,22);
  825.         s24[23] = 0;
  826.         rptstr = s24;
  827.     }
  828.     clear_area(win,5,7,22);
  829.     waddstr(win,rptstr);
  830.  
  831.     if(error_flag)
  832.     {
  833.         ++this_file_errors;
  834.         ++total_errors;
  835.         report_error_count();
  836.     }
  837.  
  838. }    /* end of report_last_txhdr */
  839.  
  840. /*+-------------------------------------------------------------------------
  841.     report_last_rxhdr(rptstr,error_flag)
  842.     5,35,22
  843. --------------------------------------------------------------------------*/
  844. void
  845. report_last_rxhdr(rptstr,error_flag)
  846. register char *rptstr;
  847. int error_flag;
  848. {
  849. char s24[24];
  850. extern int log_packets;
  851.  
  852.     if(log_packets)
  853.     {
  854.         write(log_packets,"rx:   ",6);
  855.         write(log_packets,rptstr,strlen(rptstr));
  856.         write(log_packets,"\n",1);
  857.     }
  858.  
  859.     if(strlen(rptstr) > 22)
  860.     {
  861.         strncpy(s24,rptstr,22);
  862.         s24[23] = 0;
  863.         rptstr = s24;
  864.     }
  865.     clear_area(win,5,35,22);
  866.     waddstr(win,rptstr);
  867.  
  868.     if(error_flag)
  869.     {
  870.         ++this_file_errors;
  871.         ++total_errors;
  872.         report_error_count();
  873.     }
  874.     report_window();
  875.  
  876. }    /* end of report_last_rxhdr */
  877.  
  878. /*+-------------------------------------------------------------------------
  879.     report_str(rptstr,error_flag) row 11/12 col 3 len 55
  880.  
  881.   error_flag == 0 for status/progress message
  882.              == 1 for bump error count, unless rptstr is null
  883.                   in which case, merely clear error string area
  884.              == 2 write string on bottom line (not an error)
  885.              == 3 write string on transaction line (not an error)
  886.              == -1 use error line but do not bump error count
  887. --------------------------------------------------------------------------*/
  888. void
  889. report_str(rptstr,error_flag)
  890. register char *rptstr;
  891. int error_flag;
  892. {
  893. char s60[60];
  894. extern int log_packets;
  895.  
  896.     if(strlen(rptstr) > 55)
  897.     {
  898.         strncpy(s60,rptstr,55);
  899.         s60[55] = 0;
  900.         rptstr = s60;
  901.     }
  902.  
  903.     switch(error_flag)
  904.     {
  905.         case 0:
  906.             clear_area(win,12,3,55);
  907.             break;
  908.         case 1:
  909.             ++this_file_errors;
  910.             ++total_errors;
  911.             report_error_count();
  912.         case -1:
  913.             clear_area(win,11,3,55);
  914.             break;
  915.         case 2:
  916.             clear_area(win,13,3,55);
  917.             break;
  918.         case 3:
  919.             clear_area(win,4,3,55);
  920.             break;
  921.     }
  922.  
  923.     waddstr(win,rptstr);
  924.     wrefresh(win);
  925.  
  926.     if(log_packets)
  927.     {
  928.         write(log_packets,"info: ",6);
  929.         write(log_packets,rptstr,strlen(rptstr));
  930.         write(log_packets,"\n",1);
  931.     }
  932.  
  933. }    /* end of report_str */
  934.  
  935. /*+-------------------------------------------------------------------------
  936.     report_transaction()
  937. --------------------------------------------------------------------------*/
  938. void
  939. report_transaction(str)
  940. char *str;
  941. {
  942.     report_str(str,3);
  943. }    /* end of report_transaction */
  944.  
  945. /*+-------------------------------------------------------------------------
  946.     report_file_open_tod() -- time of start of this file
  947.  
  948.   this file open time: row 8 col 41 length 8
  949. --------------------------------------------------------------------------*/
  950. void
  951. report_file_open_tod()
  952. {
  953.     clear_area(win,8,41,8);
  954.     this_file_start_seconds = time((long *)0);
  955.     waddstr(win,get_tod(1,(char *)0));
  956.     wrefresh(win);
  957. }    /* end of report_file_open_tod */
  958.  
  959. /*+-------------------------------------------------------------------------
  960.     report_file_open_mode(file_mode)
  961.   mode map: row 4 col 46 len 10
  962. --------------------------------------------------------------------------*/
  963. report_file_open_mode(file_mode)
  964. unsigned short file_mode;
  965. {
  966.     clear_area(win,3,46,10);
  967.     waddstr(win,mode_map(file_mode,(char *)0));
  968.     wrefresh(win);
  969. }    /* end of report_file_open_mode */
  970.  
  971. /*+-------------------------------------------------------------------------
  972.     report_file_open_length(long_length)
  973.   length:   row 3 col 36 len  8
  974. --------------------------------------------------------------------------*/
  975. report_file_open_length(length)
  976. long length;
  977. {
  978.     clear_area(win,3,36,8);
  979.     if(length <= 0)
  980.         waddstr(win,"unknown");
  981.     else
  982.     {
  983.         sprintf(s128,"%8lu",length);
  984.         waddstr(win,s128);
  985.     }
  986.     wrefresh(win);
  987. }    /* end of report_file_open_length */
  988.  
  989. /*+-------------------------------------------------------------------------
  990.     report_file_send_open(filename,filestat)
  991.  
  992.   filename: row 2 col 20 len 38
  993.   number:   row 2 col 8 len 3
  994.   length:   row 3 col 36 len  8
  995.   mode:     row 3 col 46 len 10
  996.   time of start of this file: row 4 col 47 length 8 hh:mm:ss
  997. --------------------------------------------------------------------------*/
  998. void
  999. report_file_send_open(filename,filestat)
  1000. char *filename;
  1001. struct stat *filestat;
  1002. {
  1003. char s50[50];
  1004. register char *cptr = filename;
  1005.  
  1006.     if(log_packets)
  1007.     {
  1008.         write(log_packets,"file: ",6);
  1009.         write(log_packets,filename,strlen(filename));
  1010.         write(log_packets,"\n",1);
  1011.     }
  1012.  
  1013.     /* number */
  1014.     clear_area(win,2,8,3);
  1015.     sprintf(s50,"%3d",Filcnt);
  1016.     waddstr(win,s50);
  1017.  
  1018.     /* filename */
  1019.     if(strlen(filename) > 38)
  1020.     {
  1021.         strncpy(s50,filename,38);
  1022.         s50[39] = 0;
  1023.         cptr = s50;
  1024.     }
  1025.     clear_area(win,2,20,38);
  1026.     waddstr(win,cptr);
  1027.  
  1028.     /* length */
  1029.     report_file_open_length(filestat->st_size);
  1030.  
  1031.     /* mode */
  1032.     report_file_open_mode(filestat->st_mode);
  1033.  
  1034.     /* time of start of this file */
  1035.     report_file_open_tod();
  1036.  
  1037.     this_file_errors = 0;
  1038.     report_error_count();
  1039. }    /* end of report_file_send_open */
  1040.  
  1041. /*+-------------------------------------------------------------------------
  1042.     report_file_rcv_started(filename,length,last_mod_time,file_mode)
  1043.  
  1044.   filenumber: row 2 col  8 len  3
  1045.               row 2 col 12 len  7 clear "of ###"
  1046.   filename:   row 2 col 20 len 38
  1047. --------------------------------------------------------------------------*/
  1048. report_file_rcv_started(filename,length,last_mod_time,file_mode)
  1049. char *filename;
  1050. long length;                    /* if < 0, "UNKNOWN" */
  1051. long last_mod_time;            /* not currently displayed */
  1052. unsigned short file_mode;        /* UNIX file modifier or zero */
  1053. {
  1054. register char *cptr;
  1055. char s50[50];
  1056.  
  1057.     if(log_packets)
  1058.     {
  1059.         write(log_packets,"file: ",6);
  1060.         write(log_packets,filename,strlen(filename));
  1061.         write(log_packets,"\n",1);
  1062.     }
  1063.  
  1064.     /* filename */
  1065.     if(strlen(filename) > 38)
  1066.     {
  1067.         strncpy(s50,filename,38);
  1068.         s50[39] = 0;
  1069.         cptr = s50;
  1070.     }
  1071.     else
  1072.         cptr = filename;
  1073.  
  1074.     clear_area(win,2,20,38);
  1075.     waddstr(win,cptr);
  1076.  
  1077.     /* file number */
  1078.     clear_area(win,2,8,3);
  1079.     sprintf(s50,"%3d",Filcnt);    /* rz uses as file number 1-n */
  1080.     waddstr(win,s50);
  1081.  
  1082. /* if remote sender provides a file count, display it */
  1083.     if(npats)
  1084.     {
  1085.         clear_area(win,2,12,7);    /* clear "of ###" */
  1086.         sprintf(s50,"of %3d:",npats);
  1087.         waddstr(win,s50);
  1088.     }
  1089.  
  1090.     /* length */
  1091.     report_file_open_length(length);
  1092.  
  1093.     /* mode */
  1094.     report_file_open_mode(file_mode);
  1095.  
  1096.     /* time of start of this file */
  1097.     report_file_open_tod();
  1098.  
  1099.     this_file_errors = 0;
  1100.     report_error_count();
  1101. }    /* end of report_file_rcv_started */
  1102.  
  1103. /*+-------------------------------------------------------------------------
  1104.     report_file_close()
  1105. --------------------------------------------------------------------------*/
  1106. void report_file_close()
  1107. {
  1108.     if(show_window)
  1109.     {
  1110.         clear_area(win,9,50,8);
  1111.         waddstr(win,"+0");
  1112.         Txpos = 0;
  1113.         Rxpos = 0;
  1114.     }
  1115.  
  1116.     report_str("End of file",0);
  1117.     wrefresh(win);
  1118.     this_file_start_seconds = 0;
  1119.  
  1120. }    /* end of report_file_close */
  1121.  
  1122. /*+-------------------------------------------------------------------------
  1123.     report_comm_baud_rate(baud_rate)
  1124.  
  1125.  baud rate: row 7 col 14 length 5
  1126. --------------------------------------------------------------------------*/
  1127. report_comm_baud_rate(baud_rate)
  1128. unsigned int baud_rate;
  1129. {
  1130.     char tstr8[8];
  1131.  
  1132.     zcurses_baud_rate = baud_rate;
  1133.     clear_area(win,7,14,5);
  1134.     if(baud_rate == 0)
  1135.         waddstr(win,"?");
  1136.     else
  1137.  
  1138.     {
  1139.         sprintf(tstr8,"%5u",baud_rate);
  1140.         waddstr(win,tstr8);
  1141.     }
  1142.     wrefresh(win);
  1143.  
  1144. }    /* end of report_comm_baud_rate */
  1145.  
  1146. /*+-------------------------------------------------------------------------
  1147.     report_file_byte_io(count)
  1148. --------------------------------------------------------------------------*/
  1149. report_file_byte_io(count)
  1150. long count;
  1151. {
  1152.  
  1153.     total_data_chars_xfered += (long)count;
  1154.     if(total_data_chars_xfered)
  1155.     {
  1156.         sprintf(s128,"Total file bytes transferred: %lu",
  1157.             total_data_chars_xfered);
  1158.         report_str(s128,-1);
  1159.     }
  1160.  
  1161. }    /* end of report_file_byte_io */
  1162.  
  1163. /* end of zcurses.c */
  1164. /* vi: set tabstop=4 shiftwidth=4: */
  1165.